﻿Imports Microsoft.ApplicationBlocks.Data
Imports System.Data.SqlClient

Public Class frmChart

    Dim ofunction As New hDCommonFunction

    Private Sub frmChart_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cboKiBaoCao.Text = "Năm nay"
        cboThongKe.Text = "Theo chức vụ"
        UltraComboEditor2.Text = "Năm nay"
        cboHopDong.Value = 1
        LoadAllCombo()
        UltraComboEditor3.Text = "Năm nay"
        cboSoLoaiHDLD.Value = 1
    End Sub

    Private Sub cboKiBaoCao_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboKiBaoCao.ValueChanged
        ofunction.XuLyThoiGian(dtTuNgay, dtDenNgay, cboKiBaoCao)
        cboThongKe_ValueChanged(sender, e)
    End Sub

    Private Sub cboThongKe_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboThongKe.ValueChanged
        If (cboThongKe.Text = "Theo giới tính") Then
            ChartGioiTinh()
        ElseIf (cboThongKe.Text = "Theo khu vực") Then
            ChartKhuVuc()
        ElseIf (cboThongKe.Text = "Theo chức vụ") Then
            ChartChucVu()
        End If
    End Sub

    Private Sub ChartGioiTinh()
        Dim ds As New DataSet
        Dim oArray As SqlParameter() = {New SqlParameter("@FROMDATE", SqlDbType.DateTime), _
                                        New SqlParameter("@TODATE", SqlDbType.DateTime)}
        oArray(0).Value = dtTuNgay.Value
        oArray(1).Value = dtDenNgay.Value
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Proc_Report_NhanVien_GioiTinh", ds, New String() {"BieuDo"}, oArray)
        UltraChart1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.PieChart
        UltraChart1.DataSource = ds.Tables("BieuDo")
    End Sub

    Private Sub ChartChucVu()
        Dim ds As New DataSet
        Dim oArray As SqlParameter() = {New SqlParameter("@FROMDATE", SqlDbType.DateTime), _
                                        New SqlParameter("@TODATE", SqlDbType.DateTime)}
        oArray(0).Value = dtTuNgay.Value
        oArray(1).Value = dtDenNgay.Value
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Proc_Report_NhanVien_ChucVu", ds, New String() {"BieuDo_1"}, oArray)
        UltraChart1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.PieChart
        UltraChart1.DataSource = ds.Tables("BieuDo_1")
    End Sub

    Private Sub ChartKhuVuc()
        Dim ds As New DataSet
        Dim oArray As SqlParameter() = {New SqlParameter("@FROMDATE", SqlDbType.DateTime), _
                                        New SqlParameter("@TODATE", SqlDbType.DateTime)}
        oArray(0).Value = dtTuNgay.Value
        oArray(1).Value = dtDenNgay.Value
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Proc_Report_NhanVien_KhuVuc", ds, New String() {"BieuDo_2"}, oArray)
        UltraChart1.DataSource = ds.Tables("BieuDo_2")
    End Sub

    Private Sub UltraComboEditor2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraComboEditor2.ValueChanged
        ofunction.XuLyThoiGian(UltraDateTimeEditor2, UltraDateTimeEditor1, UltraComboEditor2)
        cboHopDong_ValueChanged(sender, e)
    End Sub

    Private Sub LoadHopDong(ByVal iLoai As Integer)
        Dim ds As New DataSet
        Dim oArray As SqlParameter() = {New SqlParameter("@FROMDATE", SqlDbType.DateTime), _
                                        New SqlParameter("@TODATE", SqlDbType.DateTime), _
                                        New SqlParameter("@LOAIHOPDONG", SqlDbType.Int)}
        oArray(0).Value = UltraDateTimeEditor2.Value
        oArray(1).Value = UltraDateTimeEditor1.Value
        oArray(2).Value = iLoai
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Proc_Report_HopDong_LoaiHopDong", ds, New String() {"HopDong_1"}, oArray)
        grdHopDog.DataSource = ds.Tables("HopDong_1")
    End Sub

    Private Sub cboHopDong_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboHopDong.ValueChanged
        If (cboHopDong.Value = 0) Then
            LoadHopDong(1)
        ElseIf (cboHopDong.Value = 1) Then
            LoadHopDong(2)
        End If
        LoadGridView()
    End Sub

    Private Sub LoadGridViewNhanVien()
        Try
            grdNhanVien.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect
            With grdNhanVien.DisplayLayout.Bands(0)
                .Columns("SoHopDongLD").Hidden = True
                .Columns("TenHopDongLD").Hidden = True
                .Columns("NgayHetHieuLuc").Hidden = True
                .Columns("HinhThucLamViec").Hidden = True
                .Columns("MucLuongBaoHiem").Hidden = True
                .Columns("MucLuongThoaThuan").Hidden = True
                .Columns("PhuCap").Hidden = True
                .Columns("NguoiDaiDienKy").Hidden = True
                .Columns("ChucDanh").Hidden = True
                .Columns("DienGiai").Hidden = True
                .Columns("TepTinDinhKem").Hidden = True

                .Columns("MaHopDongLD").Header.Caption = "Số hợp đồng"
                .Columns("NgayKy").Header.Caption = "Ngày ký hợp đồng"
                .Columns("SoNV").Header.Caption = "Họ tên NLĐ"
                .Columns("SoViTriCV").Header.Caption = "Vị trí công việc"
                .Columns("SoLoaiHDLD").Header.Caption = "Loại hợp đồng"
                .Columns("NgayHieuLuc").Header.Caption = "Ngày hiệu lực"

                .Columns("NgayKy").Header.VisiblePosition = 1
                .Columns("MaHopDongLD").Header.VisiblePosition = 2
                .Columns("SoNV").Header.VisiblePosition = 3
                .Columns("SoViTriCV").Header.VisiblePosition = 4
                .Columns("SoLoaiHDLD").Header.VisiblePosition = 5
                .Columns("NgayHieuLuc").Header.VisiblePosition = 6
            End With

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

    End Sub

    Private Sub LoadAllCombo()
        Dim ds As New DataSet
        ds.Clear()
        If (Not ds.Tables("LoaiHopDongLD") Is Nothing) Then
            ds.Tables("LoaiHopDongLD").Rows.Clear()
        End If
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Proc_Get_LoaiHopDongLD_By_HoatDong", ds, New String() {"LoaiHopDongLD"})
        If (Not ds.Tables("LoaiHopDongLD") Is Nothing) Then
            With cboSoLoaiHDLD
                .DataSource = ds.Tables("LoaiHopDongLD")
                .DisplayMember = "TenLoaiHDLD"
                .ValueMember = "SoLoaiHDLD"
                .DisplayLayout.Load(PathLayout & "cboLoaiHopDongLD.lyt")
            End With
        End If
    End Sub

    ''Proc_Report_HopDongLD_LoaiHopDong
    Private Sub LoadHopDongLD(ByVal iLoai As Integer)
        Try
            Dim ds As New DataSet
            Dim oArray As SqlParameter() = {New SqlParameter("@FROMDATE", SqlDbType.DateTime), _
                                            New SqlParameter("@TODATE", SqlDbType.DateTime), _
                                            New SqlParameter("@LOAIHOPDONGLD", SqlDbType.Int)}
            oArray(0).Value = UltraDateTimeEditor4.Value
            oArray(1).Value = UltraDateTimeEditor3.Value
            oArray(2).Value = iLoai
            SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Proc_Report_HopDongLD_LoaiHopDong", ds, New String() {"NhanVien"}, oArray)
            grdNhanVien.DataSource = ds.Tables("NhanVien")
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

    End Sub

    Private Sub cboSoLoaiHDLD_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboSoLoaiHDLD.ValueChanged
        If (cboSoLoaiHDLD.IsItemInList) Then
            LoadHopDongLD(cboSoLoaiHDLD.Value)
            LoadGridViewNhanVien()
        End If
    End Sub

    Private Sub UltraComboEditor3_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraComboEditor3.ValueChanged
        ofunction.XuLyThoiGian(UltraDateTimeEditor4, UltraDateTimeEditor3, UltraComboEditor3)
        cboSoLoaiHDLD_ValueChanged(sender, e)
    End Sub

    Private Sub LoadGridView()
        Try
            grdHopDog.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect
            With grdHopDog.DisplayLayout.Bands(0)
                .Columns("SoHopDong").Hidden = True
                .Columns("ChucVu").Hidden = True
                .Columns("GiaTriHD").Hidden = True
                .Columns("SoLoaiTien").Hidden = True
                .Columns("SoDoiTuong").Hidden = True
                .Columns("SoTinhTrangHD").Hidden = True
                .Columns("LyDoKetThuc").Hidden = True
                .Columns("LoaiHopDong").Hidden = True
                .Columns("NguoiKy").Hidden = True


                .Columns("MaHopDong").Header.Caption = "Số hợp đồng"
                .Columns("NgayKy").Header.Caption = "Ngày ký hợp đồng"
                .Columns("NgayHieuLuc").Header.Caption = "Ngày hiệu lực"
                .Columns("NgayKetThuc").Header.Caption = "Ngày kết thúc"


                .Columns("MaHopDong").Header.VisiblePosition = 1
                .Columns("NgayKy").Header.VisiblePosition = 2
                .Columns("NgayHieuLuc").Header.VisiblePosition = 3
                .Columns("NgayKetThuc").Header.VisiblePosition = 4
            End With
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

    End Sub

End Class